# coding=utf-8

import logging
from datetime import datetime

# logging.debug("debug message")
# logging.info("info message")
# logging.warn("warn message")
# logging.error("error message")
# logging.critical("critical message")

# 记录日志到文件中

# 配置日志文件和日志级别
# logging.basicConfig(filename="output.log", level=logging.INFO)
#
#
# logging.debug("debug message")
# logging.info("info message")
# logging.warn("warn message")
# logging.error("error message")
# logging.critical("critical message")

# Logger 记录器, 提供日志相关功能的调用接口
# Handler 处理器, 将日志发送到合适的地方
# Formatter 格式化器, 指明最终输出日志记录的格式
# Filter 过滤器,  提供更好的粒度控制, 决定输出哪些日志记录

# # 代码配置
# # create logger
# logger = logging.getLogger(__name__)
#
# # set default log level
# logger.setLevel(logging.DEBUG)
#
# # 创建控制台日志处理器并设置日志级别
# consolehandler = logging.StreamHandler()
# consolehandler.setLevel(logging.DEBUG)
#
# # 创建文件日志处理器并设置日志级别
# filehandler = logging.FileHandler("output.log")
# filehandler.setLevel(logging.DEBUG)
#
# # 设置日志输出格式
# formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
#
# # 为handler处理器添加日志输出格式
# consolehandler.setFormatter(formatter)
# filehandler.setFormatter(formatter)
#
# # 为logger记录器添加处理器
# logger.addHandler(consolehandler)
# logger.addHandler(filehandler)


# 配置文件配置
# import logging.config
# import os
#
# print os.path.abspath("../configs/logging_config.ini")
#
# logging.config.fileConfig('../configs/logging_config.ini')
#
# logger = logging.getLogger(__name__)


logger = logging.getLogger("killer-platform")

consoleHandler = logging.StreamHandler()
consoleHandler.setLevel(logging.DEBUG)

path = './output/output_'

fileHandler = logging.FileHandler(path + str(datetime.now()).replace(' ', '_') + '.log', encoding='utf-8')
fileHandler.setLevel(logging.DEBUG)

formatter = logging.Formatter(
    '%(asctime)s-%(processName)s-%(process)d-%(filename)s-%(funcName)s-%(levelname)s-%(lineno)d - %(message)s')

consoleHandler.setFormatter(formatter)
fileHandler.setFormatter(formatter)

logger.setLevel(logging.DEBUG)

logger.addHandler(consoleHandler)
logger.addHandler(fileHandler)

# logger.debug("debug message")
# logger.info("info message")
# logger.warn("warn message")
# logger.error("error message")
# logger.critical("critical message")
